package com.cc.screen;

import java.nio.file.Files;
import java.nio.file.Paths;
//import java.util.Date;

/**
 * 生成字幕文件
 */
public class SubtitleGenerator {
    public static  String generateSRT(String transcription, String fileName,long seconds) throws Exception {
        // SRT文件的生成逻辑
        String[] lines = transcription.split("\n");

        StringBuilder srtContent = new StringBuilder();
        for (int i = 0; i < lines.length; i++) {
            srtContent.append(i + 1).append("\n");
            if(seconds<10){
                srtContent.append("00:00:00,000 --> 00:00:0"+seconds+",000\n"); // 示例时间
            }else{
                srtContent.append("00:00:00,000 --> 00:00:"+seconds+",000\n"); // 示例时间
            }

            srtContent.append(lines[i]).append("\n\n");
        }

        Files.write(Paths.get(fileName + ".srt"), srtContent.toString().getBytes());
        return  fileName + ".srt";
    }

//    public static void main(String[] args) throws Exception {
//        SubtitleGenerator.generateSRT("望着测验魔石碑上面闪亮得甚至有些刺眼的五个大字，少年面无表情，唇角有着一抹自嘲，紧握的手掌，因为大力，而导致略微尖锐的指甲深深的刺进了掌心之中",
//                "E:\\video\\"+new Date().getTime());
//    }
}